package treeSet;

import java.util.*;

/**
 * This program sorts a set of item by comparing their descriptions.
 */
public class TreeSetTest {

    public static void main(String[] args) {

        SortedSet<Item> parts = new TreeSet<>();
        parts.add(new Item(1234, "Toaster"));
        parts.add(new Item(4562, "Widget"));
        parts.add(new Item(9912, "Modem"));
        System.out.println(parts);

        SortedSet<Item> descriptions = new TreeSet<>(
            new Comparator<Item>() {
                public int compare(Item a, Item b) {
                    String descrA = a.getDescription();
                    String descrB = b.getDescription();
                    return descrA.compareTo(descrB);
                }
            });
        descriptions.addAll(parts);
        System.out.println(descriptions);
    }
}
